package com.bootdo.program.wallpaper.controller;

import java.util.List;
import java.util.Map;

import com.bootdo.common.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.program.wallpaper.domain.BzTagsDO;
import com.bootdo.program.wallpaper.service.BzTagsService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 标签表
 * 
 * @author guoyunfei
 * @email 2549789059@qq.com
 * @date 2021-11-06 23:50:08
 */
 
@Controller
@RequestMapping("/wallpaper/bzTags")
public class BzTagsController extends BaseController {
	@Autowired
	private BzTagsService bzTagsService;
	
	@GetMapping()
	@RequiresPermissions("wallpaper:bzTags:bzTags")
	String BzTags(){
	    return "wallpaper/bzTags/bzTags";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("wallpaper:bzTags:bzTags")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        //query.put("appid",queryAppid());
		List<BzTagsDO> bzTagsList = bzTagsService.list(query);
		int total = bzTagsService.count(query);
		PageUtils pageUtils = new PageUtils(bzTagsList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("wallpaper:bzTags:add")
	String add(){
	    return "wallpaper/bzTags/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("wallpaper:bzTags:edit")
	String edit(@PathVariable("id") Long id,Model model){
		BzTagsDO bzTags = bzTagsService.get(id);
		model.addAttribute("bzTags", bzTags);
	    return "wallpaper/bzTags/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("wallpaper:bzTags:add")
	public R save( BzTagsDO bzTags){
		String message = getMessage();
		if(null != message){
			return R.error(message);
		}
		bzTags.setValue(bzTags.getLabel());
		//bzTags.setAppid(getAppid());
		if(bzTagsService.save(bzTags)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("wallpaper:bzTags:edit")
	public R update( BzTagsDO bzTags){
		String message = getMessage();
		if(null != message){
			return R.error(message);
		}
		bzTags.setValue(bzTags.getLabel());
		//bzTags.setAppid(getAppid());
		bzTagsService.update(bzTags);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("wallpaper:bzTags:remove")
	public R remove( Long id){
		String message = getMessage();
		if(null != message){
			return R.error(message);
		}
		if(bzTagsService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("wallpaper:bzTags:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		String message = getMessage();
		if(null != message){
			return R.error(message);
		}
		bzTagsService.batchRemove(ids);
		return R.ok();
	}
	
}
